
#ifndef RGBMessage_h
#define RGBMessage_h


#include <inttypes.h>

typedef uint8_t boolean;
typedef uint8_t byte;

#define COLOURS 3
#define BYTEASSTRING 4 // 3 chars + delimiter
// first byte is the LED index,second is state
#define MESSAGE_SIZE (1+1+COLOURS*BYTEASSTRING)
// 0128001000 means set LED1={128,1,0}

#define RPOS (1+1)
#define GPOS (1+1+BYTEASSTRING)
#define BPOS (1+1+2*BYTEASSTRING)
#define LEDPOS 0
#define STATUSPOS 1


class RGBMessageReceiver {

    typedef void (*Handler)(const RGBMessageReceiver &receiver);

    public:
        RGBMessageReceiver ( const Handler messageHandler );
        void accept(byte newchar);
        void rgb(int rgb[3]) const;
        char status() const;
        byte led() const;
        const char* text() const;
    private:
        char message[MESSAGE_SIZE];
        byte next;
        Handler handler;
        boolean ready() const;
        int toNumber(int pos) const;
        
};

#endif    